package org.dromara.comm_lhz.controller;

import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.dromara.comm_lhz.entity.AsCommodityEntity;
import org.dromara.comm_lhz.entity.dto.AsCommodityInfoDto;
import org.dromara.comm_lhz.entity.vo.AsCommodityInfoVo;
import org.dromara.comm_lhz.service.AsCommodityHService;
import org.dromara.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

/**
 * 积分商城跟福利商城管理控制器
 *
 */
@RestController
@RequestMapping("/commodity")
@AllArgsConstructor
public class AsCommodityHController {

    @Autowired
    private AsCommodityHService asCommodityHService;

    /**
     * 获取积分商品列表
     *
     * @return
     */
    @GetMapping("/selCommodityList")
    public R selCommodityList(Pageable pageable,@Param("state") Integer state) {
        return R.ok(asCommodityHService.selCommodityList(pageable,state));
    }

    /**
     * 添加商品信息
     *
     * @param asCommodityInfoDto
     * @return
     */
    @PostMapping("/addCommodity")
    public void addCommodity(@RequestBody AsCommodityInfoDto asCommodityInfoDto) {
        asCommodityHService.addCommodity(asCommodityInfoDto);
    }

    /**
     * 修改商品信息
     * @param asCommodityInfoDto
     */
    @PostMapping("/updateCommodity")
    public void updateCommodity(@RequestBody AsCommodityInfoDto asCommodityInfoDto) {
        asCommodityHService.updateCommodity(asCommodityInfoDto);
    }

    /**
     * 删除商品信息
     * @param id
     */
    @DeleteMapping("/delCommodity")
    public void delCommodity(Long id) {
        asCommodityHService.removeById(id);
    }

    /**
     * 根据id获取商品信息
     * @param id
     * @return
     */
    @GetMapping("/getCommodityById")
    public R getCommodityById(Long id) {
        return R.ok(asCommodityHService.getCommodityById(id));
    }

    /**
     * 根据条件分页查询商品信息
     * @param asCommodityEntity
     * @param pageable
     * @return
     */
    @GetMapping("/selCommodity")
    public R selCommodity(AsCommodityEntity asCommodityEntity,Pageable pageable) {
        return R.ok(asCommodityHService.selCommodity(asCommodityEntity,pageable));
    }


}
